package com.kamistoat.meimeichat.meimeichatclient.socket.handlers;

import com.kamistoat.meimeichat.meimeichatclient.application.UIServiceConnector;
import com.kamistoat.meimeichat.meimeichatclient.socket.NettyClientBizHandler;
import com.kamistoat.meimeichat.meimeichatui.view.chat.IChatMethod;
import com.kamistoat.meimeichatserveraggrement.protocol.msg.MsgGroupResponse;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import javafx.application.Platform;

/**
 * 客户端处理服务器返回的 群聊消息响应
 */
public class MsgGroupHandler extends NettyClientBizHandler<MsgGroupResponse> {

    public MsgGroupHandler(UIServiceConnector uiServiceConnector) {
        super(uiServiceConnector);
    }

    /**
     * @param channel
     * @param msg
     * @Warning:子类只需要重写该方法
     */
    @Override
    public void channelRead(Channel channel, MsgGroupResponse msg) {
        IChatMethod chat = uiServiceConnector.getIChatMethod();
        Platform.runLater(() -> {
            chat.addTalkMsgGroupLeft(msg.getTalkId(), msg.getUserId(), msg.getUserNickname(), msg.getUserHead(),
                    msg.getMsgText(), msg.getMsgType(), msg.getMsgDate(), true, false, true);
        });
    }

}
